package nl.sportan.samenloop.communication.flickr;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;

import nl.sportan.samenloop.communication.PhotosetTarget;

import org.json.JSONException;

import android.util.Log;

import com.gmail.yuyang226.flickr.Flickr;
import com.gmail.yuyang226.flickr.FlickrException;
import com.gmail.yuyang226.flickr.photosets.Photoset;
import com.gmail.yuyang226.flickr.photosets.Photosets;
import com.gmail.yuyang226.flickr.photosets.PhotosetsInterface;

public class PhotosetRetriever implements Runnable {

		private PhotosetTarget target;
		
		private final static String TAG = "PhotosetRetriever";
		
		public PhotosetRetriever(PhotosetTarget target) {
			this.target = target;
		}
		
		
		public void run() {
			Flickr f = new Flickr(FlickrConstants.APIKEY);

			PhotosetsInterface psi = f.getPhotosetsInterface();

			Photosets ps;
			try {
				ps = psi.getList(FlickrConstants.FLICKR_ID);

				Collection<Photoset> sets = ps.getPhotosets();
				ArrayList<Photoset> asets = new ArrayList<Photoset>(sets);

				target.setPhotoSet(asets);
				
				Log.d(TAG, "Number of retrieved photosets: " + sets.size());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (FlickrException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			// PhotosInterface photos = f.getPhotosInterface();

		}

	}